package logic

import (
	"cart_srv/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartFlushLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartFlushLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartFlushLogic {
	return &CartFlushLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartFlushLogic) CartFlush(req *types.CartFlushRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.CartRpc.CartFlush(l.ctx, &cart.CartFlushRequest{UserId: int64(req.UserId)})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "清空失败",
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "清空成功",
	}, nil
}
